package com.digdes.calendar.gwt.client.widget;

import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.Widget;

public abstract class IntervalCalendar extends CalendarWidget {
    protected ScrollPanel scrollPanel;

    public IntervalCalendar() {
        scrollPanel = new ScrollPanel(aPanel);
        scrollPanel.setSize("1000px", "550px");
        scrollPanel.addStyleName("scrollDay");
        aPanel.setHeight("1200px");
        calendarGrid.setWidth("980px");
        mainPanel.add(scrollPanel, DockPanel.CENTER);
    }

    @Override
    final protected void drawCalendar() {
        clearWidget();
        setDataHeader();
        getEvents();
    }

    protected void clearWidget() {
        eventDTOList.clear();
        scrollPanel.scrollToTop();
        for (EventLabel label : eventLabels) {
            label.removeFromParent();
            RootPanel.get().remove(label);
        }
    }

    protected void createHourColumn(int row) {
        calendarGrid.setText(row, 0, Data.HOURS_TITLE[row]);
        calendarGrid.getCellFormatter().setStyleName(row, 0, "hours");
        calendarGrid.getCellFormatter().addStyleName(row, 0, "hoursSecond");
        calendarGrid.getCellFormatter().addStyleName(row, 0, "cellRightBorder");
    }

    protected void createDaysColumn(int row, int column) {
        calendarGrid.getCellFormatter().addStyleName(row, column, "cellRightBorder");
        gridInCell = createCellGrid();
        gridInCell.getCellFormatter().setStyleName(0, 0, "hoursFirst");
        gridInCell.getCellFormatter().setStyleName(1, 0, "hoursSecond");
        gridInCell.setWidth("100%");
        gridInCell.setHeight("50px");
        gridInCell.setCellPadding(0);
        gridInCell.setCellSpacing(0);
        calendarGrid.setWidget(row, column, gridInCell);
        gridInCell.setDayWeek(column - 1);
        gridInCell.setHour(row);
        gridInCellList.add(gridInCell);
    }

    protected abstract void drawCore();

    protected abstract void setDataHeader();

    protected abstract void getEvents();

    @Override
    protected abstract Widget getNavBar();

}
